package collections;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Created by pc on 2015/2/3.
 * BinarySearch要先排序才行，意义打了折扣*
 * Arrays.asList这个ArrayList是Arrays的内部类，与继承List接口的不同，不能add, remove,但可以set,get*
 */
public class BinarySearchDemo{
    int [] listArray = new int[] {34,123 ,21, 43, 23, 34, -8, 34};
//    Integer [] list = new Integer[] {34,123 ,21, 43, 23, 34, -8, 34};

    public static void main(String[] args) {
        BinarySearchDemo cs = new BinarySearchDemo();
        List<Integer> list = Arrays.asList(34, 2, 23, 345, 23, 34);
        list.set(1, 200 );
//        list.add(56, 6);
        Arrays.sort(cs.listArray);
        System.out.println(Arrays.toString(cs.listArray));
        System.out.println("Arrays.binarySearch: " + Arrays.binarySearch(cs.listArray, -8) );
        Collections.sort(list);
        System.out.println(list);
        System.out.println("find at: " + Collections.binarySearch(list, 23));
        
        
        List<String> sList = new ArrayList<String>(5);
        sList.add("a");
        sList.add("b");
        sList.add("c");
        String [] sArr = sList.toArray(new String[sList.size()]);
//        Object[] sArray = sList.toArray();
        System.out.println(Arrays.toString(sArr));
    }
}
